package com.example.win.android_banduyujia.peopleactivity.ui.item;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.ui.model.AlbumModel;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Win on 2015/9/17.
 */
public class AlbumItem extends LinearLayout {

    private ImageView ivAlbum, ivIndex;
    private TextView  tvName,tvCount;
    private int count;
    private String name;
    private String albumImage;

    public AlbumItem(Context context) {
        super(context);
    }

    public AlbumItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.layout_album, this, true);

        ivAlbum = (ImageView)findViewById(R.id.iv_album_la);
        ivIndex = (ImageView)findViewById(R.id.iv_index_la);
        tvName = (TextView)findViewById(R.id.tv_name_la);
        tvCount = (TextView)findViewById(R.id.tv_count_la);
    }

    public AlbumItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    /** 初始化 */
    public void update(AlbumModel album) {
        setAlbumImage(album.getRecent());
        setName(album.getName());
        setCount(album.getCount());
        isCheck(album.isCheck());
    }

    private void isCheck(boolean isCheck) {
         if(isCheck)
             ivIndex.setVisibility(View.VISIBLE);
         else
             ivIndex.setVisibility(View.GONE);
    }

    public void setCount(int count) {
        tvCount.setHint(count + "张");
    }

    public void setName(CharSequence title) {
        tvName.setText(title);
    }

    /** 设置相册封面 */
    public void setAlbumImage(String path) {
        ImageLoader.getInstance().displayImage("file://" + path, ivAlbum);
    }
}
